package com.rst.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.rst.model.Teacher;

@Repository
@Transactional
public class LibraryDAO {

	@Autowired
	private SessionFactory sessionFactory;

	public void saveTeacher(Teacher teacher) {
		 sessionFactory.getCurrentSession().saveOrUpdate(teacher);		
	}

	public Teacher getTeacherById(Long teacherId) {
	    Session session = sessionFactory.getCurrentSession();
	    Teacher teacher = (Teacher)session.get(Teacher.class, teacherId);
		return teacher;
	}

	@SuppressWarnings("unchecked")
	public List<Teacher> getTeacherList() {
		Session session = sessionFactory.getCurrentSession();
	    String str = "FROM Teacher t WHERE t.status = :status  ";
	    	
	    Query query = session.createQuery(str);
	    query.setParameter("status",  Teacher.ACTIVE);
		return query.list();
	}
}




